package lu.med.praxiswahl.wahlumed.service.beans;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Remote;
import javax.ejb.Stateless;

import lu.med.praxiswahl.wahlumed.dao.beans.daointerface.OPCodeRateDAOInt;
import lu.med.praxiswahl.wahlumed.model.beans.OPCodeRateTBL;
import lu.med.praxiswahl.wahlumed.service.beans.serviceinterface.OPCodeRateServiceInt;

/**
 * Session Bean implementation class OPCodeRateService
 */
@Stateless
@Remote({ OPCodeRateServiceInt.class })
public class OPCodeRateService implements OPCodeRateServiceInt {

	@EJB
	private OPCodeRateDAOInt opCoRaDao;

	/**
	 * Default constructor.
	 */
	public OPCodeRateService() {
	}

	@Override
	public int createOPCodeRate(String label, String description,
			String basePrice, /* String basePrice_2cl, */int priority)
			throws RuntimeException {
		OPCodeRateTBL newItem = new OPCodeRateTBL();

		newItem.setCode_label(label);
		newItem.setDescription(description);
		newItem.setBase_price(basePrice);
		// newItem.setBase_price_2cl(basePrice_2cl);
		newItem.setPriority(priority);

		opCoRaDao.persist(newItem);

		return DONE;
	}

	@Override
	public int deleteOPCodeRate(String codeLabel) throws RuntimeException {
		opCoRaDao.delete(codeLabel);
		return DONE;
	}

	@Override
	public List<OPCodeRateTBL> getAvailableCodeRates() {
		List<OPCodeRateTBL> resultList = opCoRaDao.getAvailableOPCodeRates();

		return resultList;
	}

	@Override
	public OPCodeRateTBL getCodeRate(String codeLabel) {

		return this.opCoRaDao.retrieveOPCodeRateByID(codeLabel);
	}

	@Override
	public void updateOPCodeRate(OPCodeRateTBL item) {
		this.opCoRaDao.update(item);

	}

}
